package com.android.launcher3;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class ShortcutsAdapter extends ArrayAdapter<ShortcutInfo> {
	private final IconCache mIconCache;
	private final LayoutInflater mInflater;

	/**
	 * Creates a new ShortcutsAdapter object.
	 */
	public ShortcutsAdapter(final Context context,
			final ArrayList<ShortcutInfo> apps) {
		super(context, 0, apps);
		mInflater = LayoutInflater.from(context);
		mIconCache = ((LauncherApplication) context.getApplicationContext())
				.getIconCache();
	}

	@Override
	public View getView(final int position, View convertView,
			final ViewGroup parent) {
		ShortcutInfo localShortcutInfo = (ShortcutInfo) getItem(position);

		if (convertView == null) {
			convertView = this.mInflater.inflate(R.layout.application_boxed,
					parent, false);
		}

		MenuItemView localMenuItemView = (MenuItemView) convertView;
		localMenuItemView.setImageDrawable(new FastBitmapDrawable(
				localShortcutInfo.getIcon(this.mIconCache)));
		localMenuItemView.setText(localShortcutInfo.title);
		localMenuItemView.setTag(localShortcutInfo);

		return convertView;
	}
}
